package cn.xiaomubiao.oschine.fragment.myinfofragment.message;

import android.content.Intent;
import android.util.Log;
import android.view.View;

import cn.xiaomubiao.oschine.activity.MyInfoBaseActivity;
import cn.xiaomubiao.oschine.adapter.myinfo.MyInfoBaseListAdapter;
import cn.xiaomubiao.oschine.adapter.myinfo.MyInfoMessageLeaveMessageAdapter;
import cn.xiaomubiao.oschine.bean.MessageList;
import cn.xiaomubiao.oschine.contants.Host;
import cn.xiaomubiao.oschine.fragment.myinfofragment.MyInfoBaseListFragment;
import cn.xiaomubiao.oschine.util.HttpUtil;

/**
 * @author
 * @version 1.0
 * 留言
 * @date 2017/4/5
 */

public class MyInfoMessageLeaveMessageFragment extends MyInfoBaseListFragment {

    private MessageList bean;

    protected MyInfoMessageLeaveMessageAdapter mAdapter;

    @Override
    protected MyInfoBaseListAdapter getListAdapter() {
        mAdapter = new MyInfoMessageLeaveMessageAdapter();
        mAdapter.setOnItemClickListener(new MyInfoBaseListAdapter.OnItemClickListener() {
            @Override
            public void onItemClickListener(View view, int position) {
                int idString = bean.getMessagelist().get(position).getId();
                Intent intent = new Intent(getActivity(), MyInfoBaseActivity.class);
                intent.putExtra("idString", idString + "");
                String className = null;
                if (className != null) {
                    intent.putExtra("className", className);
                }
                intent.putExtra("title", bean.getMessagelist().get(position).getFriendName());
                startActivity(intent);
            }
        });

        return mAdapter;
    }

    @Override
    protected void loadData() {
        String url = Host.HOST_GENYMOTION + "/list/message_list/page0.xml";
        HttpUtil<MessageList> httpUtil = new HttpUtil<>(getActivity(), MessageList.class);
        httpUtil.getStringData(url, new HttpUtil.OnGetDataListener<MessageList>() {
            @Override
            public void onSuccess(MessageList bloglist) {
                bean = bloglist;
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mAdapter.addDatas(bean.getMessagelist());
                    }
                });
            }

            @Override
            public void onFailure(Exception e) {
                Log.d("test", "onFailure: " + e.getMessage());
            }
        });
    }
}

